package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.bo.ProcessCheckBo;
import com.ruoyi.system.service.IProcessCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 流程审核
 *
 * @author ruoyi
 * @date 2024-04-10
 */
@Validated
@RestController
@RequestMapping("/system/check")
public class ProcessCheckController extends BaseController {
    @Autowired
     IProcessCheckService iProcessCheckService;

    /**
     * 查询流程审核列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProcessCheckBo bo) {
        return iProcessCheckService.queryPageList(bo);
    }


    /**
     * 获取流程审核详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public AjaxResult    getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return  AjaxResult.success(iProcessCheckService.queryById(id));
    }

    /**
     * 新增流程审核
     */
    @Log(title = "流程审核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult add(@Validated(AddGroup.class) @RequestBody ProcessCheckBo bo) {
        return AjaxResult.success(iProcessCheckService.insertByBo(bo));
    }

    /**
     * 修改流程审核
     */
    @Log(title = "流程审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult edit(@Validated(EditGroup.class) @RequestBody ProcessCheckBo bo) {
        return AjaxResult.success(iProcessCheckService.updateByBo(bo));
    }

    /**
     * 删除流程审核
     *
     * @param ids 主键串
     */
    @Log(title = "流程审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return AjaxResult.success(iProcessCheckService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
